package com.bpc.cs.managed.bean;

import java.io.Serializable;
import java.util.List;

import com.bpc.cs.constant.Constant;
import com.bpc.cs.managed.dvo.FactorChoiceDVO;
import com.bpc.cs.service.IFactorChoiceService;

/**
 * @author   phan_tp
 * @datetime Dec 7, 2012 : 5:18:29 PM
 */

public class FactorChoiceBean extends BaseBean implements Serializable {

	private static final long serialVersionUID = -6063350723169421013L;
	private IFactorChoiceService factorChoiceService;
	private List<FactorChoiceDVO> listFactorChoice;
	private FactorChoiceDVO selectedFactorChoice;
	private String factorChoice;
	private String score;

	/**
	 * Add new factor choice
	 */
	public void addFactorChoice() {
		RuleBean ruleBean = (RuleBean)getBean(Constant.RULE_BEAN, RuleBean.class);

		// Call factorChoiceService to add new factor
		factorChoiceService.addFactorChoice(ruleBean.getSelectedRule(), factorChoice, Integer.parseInt(score));

		// Refresh list factor choice in form add new rule
		preGetListFactorChoice();

		// Reset value null for next add new factor choice
		factorChoice = null;
		score = null;
	}

	/**
	 * Remove factorChoice
	 */
	public void removeFactorChoice() {
		// Call factorChoiceService to execute remove action
		factorChoiceService.removeFactorChoice(selectedFactorChoice.getFactorChoiceID());

		// Refresh list factor choice after delete factorchoice
		preGetListFactorChoice();

		// Reset value null for selectedFactorChoice which is removed
		selectedFactorChoice = null;
	}

	/**
	 * @return the listFactorChoice
	 */
	public void preGetListFactorChoice() {
		RuleBean ruleBean = (RuleBean)getBean(Constant.RULE_BEAN, RuleBean.class);
		// Call factorChoiceService to get all factorChoice by ruleID
		listFactorChoice = factorChoiceService.getFactorChoiceByRuleID(ruleBean.getSelectedRule().getRuleID());
	}

	/**
	 * @return the factorService
	 */
	public IFactorChoiceService getFactorChoiceService() {
		return factorChoiceService;
	}

	/**
	 * @param factorService the factorService to set
	 */
	public void setFactorChoiceService(IFactorChoiceService factorService) {
		this.factorChoiceService = factorService;
	}

	/**
	 * @return the listFactorChoice
	 */
	public List<FactorChoiceDVO> getListFactorChoice() {
		return listFactorChoice;
	}

	/**
	 * @param listFactorChoice the listFactorChoice to set
	 */
	public void setListFactorChoice(List<FactorChoiceDVO> listFactorChoice) {
		this.listFactorChoice = listFactorChoice;
	}

	/**
	 * @return the selectedFactorChoice
	 */
	public FactorChoiceDVO getSelectedFactorChoice() {
		return selectedFactorChoice;
	}

	/**
	 * @param selectedFactorChoice the selectedFactorChoice to set
	 */
	public void setSelectedFactorChoice(FactorChoiceDVO selectedFactorChoice) {
		this.selectedFactorChoice = selectedFactorChoice;
	}

	/**
	 * @return the factorChoice
	 */
	public String getFactorChoice() {
		return factorChoice;
	}

	/**
	 * @param factorChoice the factorChoice to set
	 */
	public void setFactorChoice(String factorChoice) {
		this.factorChoice = factorChoice;
	}

	/**
	 * @return the score
	 */
	public String getScore() {
		return score;
	}

	/**
	 * @param score the score to set
	 */
	public void setScore(String score) {
		this.score = score;
	}


}
